import { defineAsyncComponent } from 'vue';

const importAll = (r) => {
  let cache = {};
  for (let k in r) {
    const arr = k.split('/');
    const name = arr[arr.length - 1].replace('.vue', '');
    cache[name] = r[k];
  }
  return cache;
};

// 注册avue原生组件的配置组件
const originConfigs = importAll(import.meta.glob('./origin/*.vue'));
// 注册扩展组件的配置组件
const extendConfigs = importAll(import.meta.glob('./extend/**/*.vue'));

const Config = {
  install(Vue) {
    for (let key in originConfigs) {
      Vue.component('config-' + key, defineAsyncComponent(originConfigs[key]));
    }

    for (let key in extendConfigs) {
      Vue.component(key, defineAsyncComponent(extendConfigs[key]));
    }
  }
};
export default Config;
